package com.project.slsx;

import android.app.Application;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
import com.lzy.okgo.model.HttpParams;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.logging.Level;

import okhttp3.OkHttpClient;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        initNet();

        initBugly();

        //test git
    }

    private void initBugly() {
//        01aebac89b
        CrashReport.initCrashReport(getApplicationContext(), "01aebac89b", false);
    }

    private void initNet() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("OkGo---------->");
        loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
        loggingInterceptor.setColorLevel(Level.INFO);
        builder.addInterceptor(loggingInterceptor);

//        builder.cookieJar(new CookieJarImpl(new SPCookieStore(this)));
        HttpParams hp = new HttpParams();
        hp.put("c", "site");
        hp.put("a", "entry");
        hp.put("ctrl", "store");
        hp.put("ac", "oauth");
        hp.put("do", "web");
        hp.put("m", "we7_wmall");
        hp.put("i", "2");
        OkGo.getInstance().init(this)                       //必须调用初始化
                .setOkHttpClient(builder.build())               //建议设置OkHttpClient，不设置将使用默认的
                .setCacheMode(CacheMode.NO_CACHE)               //全局统一缓存模式，默认不使用缓存，可以不传
                .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE)   //全局统一缓存时间，默认永不过期，可以不传
                .setRetryCount(3)                               //全局统一超时重连次数，默认为三次，那么最差的情况会请求4次(一次原始请求，三次重连请求)，不需要可以设置为0
//                .addCommonHeaders(headers)                      //全局公共头
                .addCommonParams(hp);

    }
}
